<?php
/**
 * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\JSON::checkAppEnabled('calendar');
if ( !OC_USER::isLoggedIn() ) {
   jexit(jsonError('您需要先登录', null, false));
}

$calendarid = JRequest::getInt('calendarid', 0);
$jobid = JRequest::getInt('jobid', 0);
// Dont check job permission here, subaccounts should be able to view unassigned job's share event
$calendar_model = new PCalendarModelCalendar();
$app_model = new PCalendarModelApp();

$calendar = $app_model->getCalendar($calendarid, true);
if ( !$calendar ) {
   jexit(jsonError("对不起，您没有权限访问该资源！", null, false));
}
// Default is active in pipahr
if ( !$calendar_model->setCalendarActive($calendarid, 1) ) {
   jexit(jsonError($calendar_model->getError(), null, false));
}

jexit(jsonSuccess(array(
   'active' => $calendar['active'],
   'eventSource' => $calendar_model->getEventSourceInfo($calendar,$jobid),
), null, null, false));
